/**
 * @author caojj
 * @version 1.0.0.6
 */

try {FWK} catch(ex) {FWK={}};

/**
 * Cookie 对象
 * @param {String} name	键
 * @param {String} value	值
 * @param {GMTDate|Int} expires	过期时间GMT格式 或 多少毫秒后过期
 * @param {String|N/A} path
 * @param {String|N/A} domain
 */
FWK.Cookie = function(name,value,expires,path,domain){
	this.name = name;
	this.value = value;
//	this.expires = expires?expires.toGMTString():null;
	this.path = path?path:'/';
	this.domain = domain?domain:'d1xn.com';
	if (expires) {
		if (typeof(expires)=="string") {
			var d = new Date();
			d.setTime(new Date().getTime() + parseInt(expires));
			this.expires = d.toGMTString();
		}else{
			this.expires = expires.toGMTString();
		}
	}
}

/**
 * 设置Cookie
 * @param {FWK.Cookie} _c	Cookie对象
 */
FWK.Cookie.set = function(_c){
	if (!navigator.cookieEnabled) {
		//alert('不Cookie项!');
	} else {
		if (_c) {
			document.cookie = _c.name + '=' + escape(_c.value) + (_c.expires ? (';expires=' + _c.expires):"") + ';path=' + _c.path + ';domaim=' + _c.domain + ':secure';
		}
	}
}

/**
 * 读取Cookie
 * @param {String} name	Cookie键
 */
FWK.Cookie.get = function(name){	
	var reg = new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	var arr = document.cookie.match(reg);
	return arr==null? null : unescape(arr[2]);
}

//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
/*function delCookie(name){
   var date = new Date();
   date.setTime(0);
   document.cookie = name + "=a; expires=" + date.toGMTString();
   alert(document.cookie);
  }
*/

/**
 * 删除Cookie
 * @param {String} name	Cookie键
 */
FWK.Cookie.del = function(name)   {   
      var expdate = new Date(0);   
//      expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));   
      var _c = new FWK.Cookie(name,"",expdate);
      FWK.Cookie.set(_c);
}   